/*
 * @Copyright: 2016 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.config.data.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;

import com.yyfax.framework.dao.impl.BaseDaoImpl;
import com.yyfax.framework.sql.SQLFactory;
import com.yyfax.pay.config.data.dao.BankConfigExtDao;
import com.yyfax.pay.config.model.po.BankConfigExtPO;
import com.yyfax.pay.config.model.po.BankConfigPO;
import com.yyfax.pay.config.model.po.PaymentQuotaPO;

/**
 * 银行扩展信息，用于存放各个支付通道配置持久化实现
 *
 * @author changxd
 * @date 2017年05月03日 16:17:30
 * @since 1.0.0
 */
@Repository
public class BankConfigExtDaoImpl extends BaseDaoImpl<BankConfigExtPO, Integer> implements BankConfigExtDao {
	private static final String TABLE_NAME = "bank_config_ext";

	/** 方法名，该值要和bank_config_ext.xml的属性"id"保持一致 */
	private final String SQL_INSERT = "insert";

	private final String SQL_SELECT_BY_BANKCODE_AND_PAYMENT = "selectByBankCodeAndPayment";
	private final String SQL_SELECT_BY_PAYMENT_AND_BANKCODEEXT = "selectByPaymentAndBankCodeExt";
	private final String SQL_SELECT_FOR_LIST="selectForList";

	public BankConfigExtDaoImpl() {
		super(TABLE_NAME);
	}

	@Override
	public int insert(BankConfigExtPO po) {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_INSERT);
		BeanPropertySqlParameterSource sqlParameterSource = new BeanPropertySqlParameterSource(po);
		return namedParameterJdbcTemplate.update(sql, sqlParameterSource);
	}

	@Override
	public BankConfigExtPO selectByBankCodeAndPayment(String bankCode,String paymentCode) {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_SELECT_BY_BANKCODE_AND_PAYMENT);
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("bankCode", bankCode);
		params.addValue("paymentCode", paymentCode);
		return namedParameterJdbcTemplate.queryForObject(sql, params, new BeanPropertyRowMapper<BankConfigExtPO>(poClass));
	}

	@Override
	public BankConfigExtPO selectByPaymentAndBankCodeExt(String paymentCode, String bankCodeExt) {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_SELECT_BY_PAYMENT_AND_BANKCODEEXT);
		MapSqlParameterSource params = new MapSqlParameterSource();
		params.addValue("paymentCode", paymentCode);
		params.addValue("bankCodeExt", bankCodeExt);
		return namedParameterJdbcTemplate.queryForObject(sql, params, new BeanPropertyRowMapper<BankConfigExtPO>(poClass));
	}

	@Override
	public List<BankConfigExtPO> selectForList() {
		String sql = sqlFactory.getSQL(TABLE_NAME, SQL_SELECT_FOR_LIST);
		return namedParameterJdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<BankConfigExtPO>(BankConfigExtPO.class));
	}
}
